Skip to content

expects decorator #316

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 25 commits into
base: main
Choose a base branch
from
Open

expects decorator #316

wants to merge 25 commits into from

Conversation

keewis
Copy link
Member

@keewis keewis commented Aug 10, 2025

This is a reimplementation of #143 (and #203), based on inspect.signature objects to deal with the classification of args and kwargs.

Once complete, we'll be able to define functions like this:

from pint_xarray import expects, unit_registry as ureg


@expects(None, "m", ureg.s, {None: "kg", "lat": "rad"}, return_value={None: None})
def func(a, b, c, d):
    ...

and have the decorator convert any arguments to the appropriate units, or raise an error if the unit spec does not match the argument (either because the units are incompatible, or because the spec requires an xarray object but the argument is a scalar / plain array / quantity).

@keewis
Copy link
Member Author

keewis commented Aug 10, 2025

cc @TomNicholas, in case you're still interested (it's been 3-4 years)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

@ureg.wraps decorator
1 participant